        
    
$(function(){
	//定义layui模块目录
	layui.config({
	    base: 'static/layui/lay/modules',
	    version: new Date().getTime()		
	});
	
	//填充主界面空白部分
	$(window).on('resize', function () {
	    var $content = $('.layui-body .layui-tab-content');
	    $content.height($(this).height() - 157);
	}).resize();
	
	//获取左侧菜单
	$.ajax({
		type:"get",
		url:"json/menu.json",
		async:false,
		success: function(data){
			//  <li class="layui-nav-item"><a href="">云市场</a></li>
			var tree = $("#menu");
			data.forEach(function(item){
				var $li = $('<li class="layui-nav-item"></li>');
				var $topMenu = $('<a href="javascript:;">' +
								'<i class="' + item.icon + '"></i>' +
								'<cute>' + item.title + '</cute>' + 
								'</a>');
				$li.append($topMenu);
				item.children.forEach(function(subItem){
					var $dl = $('<dl class="layui-nav-child"></dl>');
					var $dd = $('<dd></dd>').data({"url":subItem.url,"id":subItem.id});
					var $a = $('<a href="javascript:;">' +
								'<i class="fa fa-address-book"></i>' +
								'<cute>' + subItem.title + '</cute>' + 
								'</a>');
					$dl.append($dd.append($a));
					$li.append($dl);
				});
				
				tree.append($li);
			});
		}
	});		

	//给左侧菜单栏增加效果,绑定事件
	layui.use([ 'element'], function(){
		var element = layui.element;
		element.on('nav(menu)', function(elem){
			var url = elem.data('url');
			var id = elem.data('id');
			$.ajax({
				type:"GET",
				url: url,
				async:true,
				success: function(html){
					element.tabAdd('container', {
						title: elem.text(),
						content: html,
						id: id
					});					
				}
			});
		});
	
	});
});
